﻿using System;
using System.Web.UI;
using UDS.Components;

namespace UDS.SubModule.Login
{
    /// <summary>
    /// checkout 的摘要说明。
    /// </summary>
    public partial class CheckOutPage : Page
    {
        protected override void OnLoad(EventArgs e)
        {
            var now = DateTime.Now;
            var userId = SiteContext.Current.UserID;
            var dutyTime = WA_Setting.GetStaffDutyTime(userId, now);
            if (dutyTime.OffDutyTime != DateTime.MinValue)
            {
                // 未完成考勤，检查是否早退
                if (now.TimeOfDay >= dutyTime.OffDutyTime.TimeOfDay)
                {
                    // 没有早退
                    WA_Duty.RecordOffDutyData(userId, now, true, "");

                    // 弹出新页面表示成功
                    Response.Write("<script language=javascript>window.open('../WorkAttendance/checksucessful.aspx?login=out','_blank','height=200,width=400,status=no,toolbar=no,menubar=no,location=no')</script>");
                }
                else
                {
                    // 早退
                    Response.Write("<script language=javascript>location.href='../WorkAttendance/Default.aspx?notnormal=1&login=out';</script>");
                }
            }
            Response.Write("<script>window.parent.parent.location.href='logout.aspx';</script>");

#if false
            // 考勤操作
            var wd = new WA_Duty(SiteContext.Current.UserID);
            int DutyStat = wd.HaveCompletedDuty(DateTime.Now);
            //检查当天是否已经完成上班考勤
            if ((DutyStat != -1) && (DutyStat != 0))
            {
                if (wd.CheckStatus(DutyAction.OffDuty)) //没有早退
                {
                    wd.RecordOffDutyData(DutyStat, DateTime.Now, true, "");
                    //弹出新页面表示成功
                    Response.Write("<script language=javascript>window.open('../WorkAttendance/checksucessful.aspx?login=out','_blank','height=200,width=400,status=no,toolbar=no,menubar=no,location=no')</script>");
                }
                else //早退
                {
                    //跳转到填写理由页面
                    Response.Write("<script language=javascript>location.href='../WorkAttendance/Default.aspx?notnormal=1&login=out';</script>");
                }
            }
            Response.Write("<script>window.parent.parent.location.href='logout.aspx';</script>");
#endif


            base.OnLoad(e);
        }

#if false
        private void btnexit_Click(object sender, EventArgs e)
        {
            Server.Transfer("logout.aspx");
        }

        private void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
        }
#endif
    }
}